/**
 *  *2010-5-27 上午01:40:01  add 
 */
package com.base.myproject.client.busi.service;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseSimpleCombox;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.Widget;

/**
 * 服务类型，加入了类型
 * @author Administrator
 *2010-5-27
 * javazgw@gmail.com
 */
public class ServiceItemPanelType extends BaseJDBCPanel{
	BaseStore<BusiObject> itemstore ;
	BaseGridPanel 	s_service_item_grid;
	public ServiceItemPanelType()
	{
		super();
		init();
	}
	
	protected void init()
	{
		
		this.setWidth("1024px");
		
		this.setAutoHeight(true);
		
		
		this.add(initWidgetx());
		
		registerMainStore(itemstore);
		registerStore(itemstore);
	}
	public Widget initWidgetx()
	{
		CreateServiceItemStore();
		CreateServiceItemGrid();
		return s_service_item_grid;
		
	}
	
	
	void CreateServiceItemStore(){
		
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.addField("service");
		type.addField("price");
		type.addField("priceunit");
		type.addField("type");
		
		type.getField("service").setType(String.class);
		type.getField("price").setType(Double.class);
		type.getField("priceunit").setType(String.class);
		// type.addField("Phone");
		// type.addField("imagepath");
		StoreInfo info = new StoreInfo();
		info.setTablename("s_service");
		info.setForcenolimit("true");
		info.setSql("select * from s_service ");
		info.setKeyname(new String[] { "icode" });
		
		itemstore = new BaseStore<BusiObject>(type,info);

	
	}
	void CreateServiceItemGrid()
	{
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		
		
		ColumnConfig c1 = new ColumnConfig("service", "服务类型", 200);
		TextField<String> c1t = new TextField<String>();
		c1.setEditor(new CellEditor(c1t));
		
		ColumnConfig price = new ColumnConfig("price", "单价", 100);
		// TextField<String> uprictext = new TextField<String>();
		// upric.setEditor(new CellEditor(uprictext));
		price.setAlignment(HorizontalAlignment.RIGHT);
		price.setNumberFormat(NumberFormat.getCurrencyFormat());
		price.setEditor(new CellEditor(new NumberField()));
		price.getEditor().getField().setName("price");
	//	upric.getEditor().getField().addListener(Events.Change, this);
		//upric.getEditor().addListener(Events.Complete, this);
	
		ColumnConfig priceunit = new ColumnConfig("priceunit", "单位", 100);
		TextField<String> priceunittext = new TextField<String>();
		priceunit.setEditor(new CellEditor(priceunittext));
		
		ColumnConfig type = new ColumnConfig("type", "类型", 100);
		BaseSimpleCombox bsc3 =new BaseSimpleCombox("name","dictionary"," where type ='s_type'");
		type.setEditor(bsc3.getCellEditor());
		
		
		columns.add(c1);
		columns.add(price);
		columns.add(priceunit);
		columns.add(type);
		ColumnModel cm = new ColumnModel(columns);
		 s_service_item_grid = new BaseGridPanel(itemstore, cm,true,true);
		 cbs.setSelectionMode(SelectionMode.SINGLE);
		 s_service_item_grid.getBg().setSelectionModel(cbs);
		 s_service_item_grid.getBg().setHeight(400);
	}

}
